layui.use(['element', 'form', 'upload', 'layer', 'slider', 'colorpicker'], function () {
    debugger
    var $ = layui.jquery
        , element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
    var form = layui.form;
    var slider = layui.slider;
    var colorpicker = layui.colorpicker;
    var data = [];

    //session数据获取
    var itemid = sessionStorage.getItem('itemid');
    var type = sessionStorage.getItem('type');
    var layerw = window.parent.sgworld.ProjectTree.getObject(itemid);
    var CreateType = "";
    if (layerw.item == undefined) {
        return;
    }
    var datacollection = layerw.getLegend();
    if (datacollection == null || datacollection.length <= 0) {
        return;
    }
    if (type == "polylineLayer" || type == "polylineVolumeLayer" || type == "polylineWallLayer") {
        CreateType = "polyline";
    } else if (type == "pointLayer") {
        CreateType = "pointLayer";
    } else if (type == "pointLayers") {
        CreateType = "pointLayers";
    } else if (type == "labelPointLayer") {
        CreateType = "labelPointLayer";
    } else if (type == "polygonLayer") {
        CreateType = "polygonLayer";
    }
    //data = unique(data);
    var datacollectioncl = unique(datacollection);
    DataLoading(datacollectioncl, CreateType, layerw.treeobj.name);
})
//数据加载
function DataLoading(data, CreateType, name){
    var divs = document.getElementById("nc");
    divs.innerHTML = name;
    var div = document.getElementById("sj");
    for (var i = 0; i < data.length; i++) {
        var row = document.createElement('tr');
        var td = document.createElement('td');
        if (CreateType == "polyline" ) {
            var div1 = document.createElement('div');
            div1.style.width="100px";
            div1.style.height="1px";
            div1.style.backgroundColor="rgb(" + data[i].material + ")";
        }
        else if (CreateType == "lable" || CreateType == "pointLayers") {
            var div1 = document.createElement('div');
            div1.innerHTML = "lable";
            div1.style.color = "rgb(" + data[i].fillColor + ")";
        }
        else if (CreateType == "pointLayer") {
            var div1 = document.createElement('div');
            div1.style.width="20px";
            div1.style.height="20px";
            // div1.style.borderRadius="50%";
            div1.style.backgroundColor = "rgb(" + data[i].fillColor + ")";
        } else if (CreateType == "polygonLayer") {
            var div1 = document.createElement('div');
            div1.style.width="20px";
            div1.style.height="20px";
            div1.style.backgroundColor = "rgb(" + data[i].fillColor + ")";
        }
        td.appendChild(div1);
        row.appendChild(td);
        div.appendChild(row);
    }
}
//数组转对象
function unique(data) {
    var da = [];
    for (var key in data) {
        var obj = {};
        if (data[key].indexOf(";") != -1) {
            var ds = data[key].split(";");
            for (var key1 in ds) {
                obj[(ds[key1].split(":")[0])] = ds[key1].split(":")[1];
            }
        } else {
            obj[(data[key].split(":")[0])] = data[key].split(":")[1];
        }
        da.push(obj);
    }
    return da;
}